package com.xiaojian.pick.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xiaojian.pick.entity.Support;
import com.xiaojian.pick.page.AjaxResult;
import com.xiaojian.pick.service.SupportService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author whycode
 * @title: SupportController
 * @projectName campus-secondary-market-app---sys
 * @description: TODO
 * @date 2022/3/2615:56
 */

@RequestMapping("/support")
@RestController
public class SupportController {

    @Resource
    private SupportService service;

    @PostMapping("/add")
    @ResponseBody
    public AjaxResult add(@RequestBody Support support){
        service.save(support);
        return new AjaxResult(true);
    }

    @DeleteMapping("/del")
    public AjaxResult delete(@RequestBody Support support){
        service.delete(support);
        return new AjaxResult(true);
    }

    @GetMapping("/query")
    public AjaxResult query(@RequestParam Integer cId,
                            @RequestParam Integer uId){
        List<Support> list = service.list(new QueryWrapper<Support>().eq("c_id", cId)
                .eq("u_id", uId));
        if(list != null && list.size() > 0){
            return new AjaxResult(true).setData(true);
        }else{
            return new AjaxResult(true).setData(false);
        }
    }


}
